package com.poly.polyarr_;

public class PolyArray {
    public static void main(String[] args) {

        Person[] persons = new Person[5];
        persons[0] = new Person("anna",18);
        persons[1] = new Student("betty",19,69);
        persons[2] = new Student("cindy",19,78);
        persons[3] = new Teacher("smith",35,20000);
        persons[4] = new Teacher("sam",49,30000);

        //循环遍历多态数组，调用say
        for (int i = 0; i < persons.length; i++) {
            System.out.println(persons[i].say());
            if(persons[i] instanceof Student){
                ((Student)persons[i]).study();
            }else if(persons[i] instanceof Teacher){
                ((Teacher)persons[i]).teach();
            }else if(persons[i] instanceof Person){

            }else {
                System.out.println("你的类型有误");
            }
        }

    }
}
